﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ICore;
using EntityFrameWorkAccess;

namespace TestAutofac.Controllers
{
    public class CategoryController : Controller
    {
        private IDinnerService dinnerService = null;
        private ICategoryService categoryService = null;

        public CategoryController(IDinnerService dinnerService, ICategoryService categoryService)
        {
            this.dinnerService = dinnerService;
            this.categoryService = categoryService;
        }

        //
        // GET: /Category/

        public ViewResult Index()
        {
            return View(categoryService.GetAll());
        }

        //
        // GET: /Category/Details/5

        public ViewResult Details(long id)
        {
            Category category = categoryService.GetById(id);
            return View(category);
        }

        //
        // GET: /Category/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Category/Create

        [HttpPost]
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                categoryService.Add(category);
                return RedirectToAction("Index");
            }

            return View(category);
        }

        //
        // GET: /Category/Edit/5

        public ActionResult Edit(long id)
        {
            Category category = categoryService.GetById(id);
            return View(category);
        }

        //
        // POST: /Category/Edit/5

        [HttpPost]
        public ActionResult Edit(Category category)
        {
            if (ModelState.IsValid)
            {
                categoryService.Save(category);
                return RedirectToAction("Index");
            }
            return View(category);
        }

        //
        // GET: /Category/Delete/5

        public ActionResult Delete(long id)
        {
            Category category = categoryService.GetById(id);
            return View(category);
        }

        //
        // POST: /Category/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(long id)
        {
            categoryService.Delete(id);
            return RedirectToAction("Index");
        }
    }
}